// pages/myzizhijingying/myzizhijingying.js
var app = getApp();
var upimg = require('../upimg.js');
var c = require('../common.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    idcardF: '../img/zheng.png',
    idcardB: '../img/bei.png',
    idcardH: '../img/ren.png',
    zz1: '../img/addimg.png'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var email = options.email;
    var idcord = options.idcord;
    var name = options.name;
    var phone = options.phone;
    var twoinfo_id = options.twoinfo_id;
    var user_id = options.user_id;
    this.setData({
      email: email,
      idcord: idcord,
      name: name,
      phone: phone,
      twoinfo_id: twoinfo_id,
      user_id: user_id,
    });
    var sql = 'w(user_id=' + user_id + ')f(phone)l(1)';
    var that = this;
    c.ajax(
      app.dbs + 'user', {
        sql: sql
      },
      res => {
        that.setData({
          phone: res.data.phone
        });
      }
    )
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  /**
 * 用户点击右上角分享
 */
  onShareAppMessage: function () {

  },
  simpleUpload: function (e) {
    var info = e.currentTarget.dataset.info;
    var path = 'user/' + this.data.phone + info + '.png';
    var that = this;
    var key = info;
    var keyimg = info + 'img';
    var returninfo = upimg.simpleUpload(
      path,
      function (res) {
        that.setData({
          [key]: res[0].imgLocation,
          [keyimg]: res[0].dbs
        });
      }
    );


  },
  formSubmit: function (e) {
    var email = this.data.email;
    var idcord = this.data.idcord;
    var name = this.data.name;
    var phone = this.data.phone;
    var twoinfo_id = this.data.twoinfo_id;
    var user_id = this.data.user_id;
    var idcardF = this.data.idcardFimg;
    var idcardB = this.data.idcardBimg;
    var idcardH = this.data.idcardHimg;
    var zz1 = this.data.zz1img;

    c.ajax(
      app.url + 'fromsubmitjingying', {
        twoinfo_id: twoinfo_id,
        phone: phone,
        name: name,
        idcord: idcord,
        email: email,
        user_id: user_id,
        idcardF: idcardF,
        idcardB: idcardB,
        idcardH: idcardH,
        zz1: zz1
      },
      res => {
        wx.showToast({
          title: '提交成功,等待审核',
          icon: 'none',
        })
        setTimeout(function () {
          wx.switchTab({
            url: '/pages/my/index',
          })
        }
          , 2000)
      }


    )

  }
})